#include <iostream>
#include <algorithm>
using namespace std;
struct Meeting{
	int begin;
	int end;
};
bool comp(Meeting x,Meeting y){
	if (x.end == y.end) 
		return x.begin<y.begin;
	return x.end<y.end;
}

int main(){
	int n;
	cin>>n;
	Meeting d[n];
	for(int i=0; i<n; i++){
		cin>>d[i].begin>>d[i].end;
	}
	sort(d,d+n, comp);
	int y = 0;
	int count = 0;
	for(int pos=0; pos<n; pos++){
		if(d[pos].begin >= y){
			y = d[pos].end;
			count ++;
		}
	} 
	cout<<count;
} 
